<template>
  <view class="my-page">
    <!-- 顶部用户信息区域 -->
    <view class="user-info">
      <view style="display: flex;">
        <view class="avatar-wrap">
          <image class="avatar" src="/static/avatar.png" mode="aspectFit" style="width: 48rpx; height: 48rpx;"></image>
          <image class="edit-icon" src="/static/edit-icon.png" mode="aspectFit"></image>
        </view>
        <view class="login-btn" @click="handleLogin">去登录</view>
      </view>
      <view class="action-icons">
        <image class="icon" src="/static/notice-icon.png" mode="aspectFit"></image>
        <image class="icon" src="/static/setting-icon.png" mode="aspectFit"></image>
      </view>
    </view>

    <!-- 任务状态标签栏 -->
    <view class="task-tabs">
      <text 
        class="tab-item" 
        :class="{ active: currentTab === 0 }"
        @click="switchTab(0)"
      >
        我制作的任务
      </text>
      <text 
        class="tab-item" 
        :class="{ active: currentTab === 1 }"
        @click="switchTab(1)"
      >
        我发布的任务
      </text>
    </view>

    <!-- 任务状态统计 -->
<!-- 任务状态统计 -->
<view class="task-stats">
  <view class="stat-item" v-for="(stat, index) in taskStats[currentTab]" :key="index">
    <text class="stat-num">{{ stat.num }}</text>
    <text class="stat-desc">{{ stat.desc }}</text>
  </view>
</view>

    <!-- 功能列表 -->
    <view class="function-list">
      <view class="function-item" v-for="(item, index) in functionItems" :key="index" @click="handleFunctionItemClick(index)">
        <image class="item-icon" :src="item.icon" mode="aspectFit"></image>
        <text class="item-text">{{ item.text }}</text>
        <image class="arrow-icon" src="/static/arrow-icon.png" mode="aspectFit"></image>
        <text class="tag" v-if="item.tag">{{ item.tag }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';
// import { navigateTo } from 'uni-app';
// 当前选中的 tab，0 = 我制作的任务，1 = 我发布的任务
const currentTab = ref(1);

// 任务状态统计数据（示例，每个 tab 单独一组）
const taskStats = ref([
  // 我制作的任务
  [
    { desc: '报价中', num: 2 },
    { desc: '制作中', num: 1 },
    { desc: '审核中', num: 3 },
    { desc: '已完成', num: 1 },
    { desc: '已下架', num: 1 }
  ],
  // 我发布的任务
  [
    { desc: '报价中', num: 1 },
    { desc: '制作中', num: 2 },
    { desc: '审核中', num: 1 },
    { desc: '已完成', num: 2 },
    { desc: '已下架', num: 1 }
  ]
]);

// 切换 tab 方法
const switchTab = (index) => {
  currentTab.value = index;
};

// 任务状态统计数据
// const taskStats = ref([
//   { desc: '报价中' },
//   { desc: '制作中' },
//   { desc: '审核中' },
//   { desc: '已完成' },
//   { desc: '已下架' }
// ]);

// 功能列表数据
const functionItems = ref([
  { icon: '/static/commission-icon.png', text: '我的佣金' },
  { icon: '/static/wallet-icon.png', text: '我的钱包' },
  { icon: '/static/attention-icon.png', text: '我的关注' },
  { icon: '/static/browse-icon.png', text: '浏览记录' },
  { icon: '/static/feedback-icon.png', text: '建议&反馈', tag: '建议有奖' },
  { icon: '/static/service-icon.png', text: '联系客服' },
  { icon: '/static/qa-icon.png', text: 'Q&A' }
]);

// 去登录
const handleLogin = () => {
  uni.navigateTo({
    url: '/pages/login/login'
  })
};

// 点击功能项（可根据实际需求扩展）
const handleFunctionItemClick = (index) => {
  const item = functionItems.value[index];

  switch (item.text) {
    case '我的关注':
      uni.navigateTo({
        url: '/pages/follow/follow' // 替换为你的我的关注页面路径
      });
      break;
    // 其他功能项...
    default:
      uni.showToast({
        title: '功能未开放',
        icon: 'none'
      });
      break;
  }
};

</script>

<style scoped>
.my-page {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f5f5;
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 176rpx 30rpx 30rpx 30rpx;
  
  background: linear-gradient(to bottom, #00bfa5, #e0f7ef);
}

.avatar-wrap {
  position: relative;
  background-color: #F7F9FB;
  border-radius: 112rpx;
  width: 112rpx;
  height: 112rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
}

.edit-icon {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 30rpx;
  height: 30rpx;
  background-color: #00bfa5;
  border-radius: 50%;
}

.login-btn {
  font-size: 36rpx;
  color: #333;
  height: 120rpx;
  line-height: 180rpx;
  margin-right: 20rpx;
  margin-left: 30rpx;
}

.action-icons {
  display: flex;
}

.icon {
  width: 40rpx;
  height: 40rpx;
  margin-left: 30rpx;
}

.task-tabs {
  display: flex;
  border-bottom: 1px solid #eee;
  padding: 0 30rpx;
  background-color: #fff;
}

.tab-item {
  flex: 1;
  text-align: center;
  font-size: 30rpx;
  color: #999;
  padding: 20rpx 0;
}

.tab-item.active {
  color: #00bfa5;
  font-weight: bold;
  border-bottom: 2px solid #00bfa5;
}

.task-stats {
  display: flex;
  justify-content: space-around;
  padding: 30rpx;
  background-color: #fff;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 10rpx;
}

.stat-desc {
  font-size: 24rpx;
  color: #999;
}

.function-list {
  margin: 20rpx;
  background-color: #fff;
  border-radius: 20rpx;
  overflow: hidden;
}

.function-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30rpx;
  border-bottom: 1px solid #eee;
}

.item-icon {
  width: 40rpx;
  height: 40rpx;
  margin-right: 20rpx;
}

.item-text {
  flex: 1;
  font-size: 30rpx;
  color: #333;
}

.arrow-icon {
  width: 20rpx;
  height: 30rpx;
  margin-right: 10rpx;
}

.tag {
  font-size: 24rpx;
  color: #00bfa5;
  background-color: #e6f7ef;
  padding: 5rpx 15rpx;
  border-radius: 20rpx;
}

.bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #eee;
  padding: 15rpx 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.nav-icon {
  width: 40rpx;
  height: 40rpx;
}

.nav-text {
  font-size: 24rpx;
  color: #999;
  margin-top: 5rpx;
}

.nav-item.active .nav-text {
  color: #00bfa5;
}
</style>
